const { defineConfig } = require("@vue/cli-service");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const path = require("path");

module.exports = defineConfig({
  transpileDependencies: true,
  publicPath: "./",
  devServer: {
    open: false /*自动打开浏览器*/,
    host: "0.0.0.0" /*使所有的IP都可访问*/,
    port: 8080,
    /*使用代理*/
    proxy: {
      "/api": {
        target: "https://10.112.38.20:30001", // 后端接口地址
        changeOrigin: true, // needed for virtual hosted sites
        withCredentials: true,
        pathRewrite: {
          "^/api": "", // rewrite path
        },
      },
      "/getDB": {
        // 新增代理配置
        target: "http://10.112.51.79:39898",
        changeOrigin: true,
        pathRewrite: {
          "^/getDB": "",
        },
      },
      // '/ws': { // 这里的 '/ws' 是你前端请求 WebSocket 时的路径前缀，根据实际情况修改
      //   target: 'http://10.112.51.79:38414', // 后端 WebSocket 服务的真实地址
      //   ws: true, // 表明是代理 WebSocket 连接
      //   changeOrigin: true // 允许跨域 }
      // }
    },
  },
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "scss",
      patterns: [],
    },
  },
  configureWebpack: {
    output: {
      sourcePrefix: " ",
    },
    amd: {
      toUrlUndefined: true,
    },
    resolve: {
      alias: {
        "@": path.resolve("src"),
      },
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          use: {
            loader: "@open-wc/webpack-import-meta-loader",
          },
        },
        {
          test: /\.(glb|gltf)?$/,
          use: {
            loader: "url-loader",
          },
        },
      ],
    },
    externals: {
      BMap: "BMap",
      BMap_Symbol_SHAPE_POINT: "BMap_Symbol_SHAPE_POINT",
    },
  },
});
